package dao.task;

import java.util.List;

import entity.task.*;
import dao.core.*;
import entity.tasktype.*;
import entity.user.*;

public class TaskDAO extends GenericHibernateDAO<Task, Long> {

	public TaskDAO() {
		super(Task.class);
	}
	
	@SuppressWarnings("unchecked")
	public List<Task> findByTaskType(TaskType taskType) {

		return getSession()
				.createQuery(new StringBuilder()
								.append("from Task t")
								.append(" where t.taskType.id = :id")
								.toString())
				.setParameter("id", taskType.getId() )
				.list();

	}
	
	@SuppressWarnings("unchecked")
	public List<Task> findByUser(User user, String fulfill) {

		return getSession()
				.createQuery(new StringBuilder()
								.append("from Task t")
								.append(" where t.user.id = :id and fulfill = :fulfill")
								.toString())
				.setParameter("id", user.getId() )
				.setParameter("fulfill", fulfill)
				.list();

	}

}